﻿Public Class LayDLExcelNhanVien

    Private Sub btnChonFileExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChonFileExcel.Click
        Dim _openFileDialog As OpenFileDialog = New OpenFileDialog()

        _openFileDialog.InitialDirectory = "c:\Program Files"

        _openFileDialog.Filter = "Microsoft Excel Worksheet (*.xls)|*.xls"
        _openFileDialog.FilterIndex = 1
        _openFileDialog.RestoreDirectory = True

        If _openFileDialog.ShowDialog() = DialogResult.OK Then

            Dim path As String = _openFileDialog.FileName

            If (path <> "") Then

                Dim SheetName As String = "DEMO"
                Dim DtSet As DataTable = Excel_BUS.LayDLTuExceNguoiThue(path, SheetName)
                DataGridView1.DataSource = DtSet

            End If
        End If
    End Sub

    Private Sub btnLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLuu.Click
        Dim nhanvien As New NhanVien_DTO
        Dim i As Integer
        i = DataGridView1.Rows.Count()

        Dim diem As Integer = 1
        For w = 0 To i - 1

            If diem = i Then
                MessageBox.Show("Bạn đã lưu thành công!")
                Exit For
            End If
            'nhanvien.MaQL = DataGridView1.CurrentRow.Cells(0).FormattedValue.ToString()
            nhanvien.HoTenQL = DataGridView1.CurrentRow.Cells(1).FormattedValue.ToString()
            nhanvien.DienThoai = DataGridView1.CurrentRow.Cells(3).FormattedValue.ToString()
            nhanvien.DiaChi = DataGridView1.CurrentRow.Cells(2).FormattedValue.ToString()
            nhanvien.TenQuanLy = DataGridView1.CurrentRow.Cells(4).FormattedValue.ToString()
            'NguoiThue_BUS.ThemNguoithueTuExcel(nguoithue)
            Dim k As Boolean = NhanVien_BUS.LayDLExcelNhanVien(nhanvien)
            If k = False Then
                Exit For
            End If
            DataGridView1.Rows.RemoveAt(0)
            diem = diem + 1
        Next

    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
End Class